package org.jsola.hr.helper;

import org.jsola.common.SafeKit;
import org.jsola.hr.dto.SocDispatchCompanyAddDTO;
import org.jsola.hr.dto.SocDispatchCompanyUpdateDTO;
import org.jsola.hr.entity.SocDispatchCompanyDO;
import org.jsola.hr.query.SocDispatchCompanyQuery;
import org.jsola.hr.service.ISocDispatchCompanyService;
import org.jsola.hr.vo.SocDispatchCompanyVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import java.util.List;

import static org.jsola.hr.core.AbstractTest.SITE_ID;



/**
 * 社保派单公司记录表
 *
 * @author zhr
 */
@Component
public class SocDispatchCompanyTestHelper extends BaseTestHelper {
    
    @Autowired
    private ISocDispatchCompanyService socDispatchCompanyService;

    /**
     * 生成add测试数据
     * @return SocDispatchCompanyAddDTO
     */
    public SocDispatchCompanyAddDTO getSocDispatchCompanyAddDTO(){
        SocDispatchCompanyAddDTO socDispatchCompanyAddDTO = new SocDispatchCompanyAddDTO();
        socDispatchCompanyAddDTO.setYear(getRandomValue("varchar",12));
        socDispatchCompanyAddDTO.setMonth(getRandomValue("varchar",10));
        socDispatchCompanyAddDTO.setCompanyId(getRandomValue("varchar",32));
        socDispatchCompanyAddDTO.setName(getRandomValue("varchar",100));
        socDispatchCompanyAddDTO.setAddOrLess(SafeKit.getBoolean(getRandomValue("tinyint",1)));
        socDispatchCompanyAddDTO.setSocDispatchId(getRandomValue("varchar",32));
        socDispatchCompanyAddDTO.setChildCompanyId(getRandomValue("varchar",32));
        return socDispatchCompanyAddDTO;
    }


    /**
     * 生成update测试数据
     * @return SocDispatchCompanyUpdateDTO
     */
    public SocDispatchCompanyUpdateDTO getSocDispatchCompanyUpdateDTO(SocDispatchCompanyVO socDispatchCompanyVO){
        return socDispatchCompanyService.selectDOById(socDispatchCompanyVO.getId(), SITE_ID).to(SocDispatchCompanyUpdateDTO.class);
    }

    /**
     * 生成查询数据
     * @return SocDispatchCompanyQuery
     */
    public SocDispatchCompanyQuery getSocDispatchCompanyQuery() {
        SocDispatchCompanyQuery socDispatchCompanyQuery = new SocDispatchCompanyQuery();
        List<SocDispatchCompanyDO> socDispatchCompanyDOList = socDispatchCompanyService.list(new SocDispatchCompanyDO(),SITE_ID);
        if (!CollectionUtils.isEmpty(socDispatchCompanyDOList)) {
            SocDispatchCompanyDO socDispatchCompanyDO = socDispatchCompanyDOList.get(0);
            socDispatchCompanyQuery = socDispatchCompanyDO.to(SocDispatchCompanyQuery.class);
        }
        return socDispatchCompanyQuery;
    }

    /**
     * 保存示例
     * @return SocDispatchCompanyVO
     */
    public SocDispatchCompanyVO saveSocDispatchCompanyExample(){
        SocDispatchCompanyAddDTO addDTO = this.getSocDispatchCompanyAddDTO();
        SocDispatchCompanyVO socDispatchCompanyVO = socDispatchCompanyService.save(addDTO,buildTokenUser());
        return socDispatchCompanyVO;
    }


}

